from paddleocr import PaddleOCR
import os
import time  # 导入time模块

# os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'  # 我的电脑因为报某些错误需要加上这个

# 初始化PaddleOCR
ocr = PaddleOCR(use_angle_cls=False, lang="ch", use_gpu=True)  # need to run only once to download and load model into memory

img_path = 'D:/Project/All_Project/Python/blct/imges/1.png'

# 记录推理开始时间
start_time = time.time()
print("正在执行OCR推理...")

# 进行OCR推理
result = ocr.ocr(img_path, cls=True)

# 记录推理结束时间
end_time = time.time()

# 计算推理时间
inference_time = end_time - start_time
print(f"推理时间: {inference_time:.4f} 秒")

# 输出OCR结果
for idx in range(len(result)):
    res = result[idx]
    for line in res:
        print(line)